package com.team2.outpatient_sys.web.pharmacyControllers;

import com.github.pagehelper.PageInfo;
import com.team2.outpatient_sys.pojo.Doctor;
import com.team2.outpatient_sys.pojo.PrescriptionAndName;
import com.team2.outpatient_sys.pojo.Result;
import com.team2.outpatient_sys.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/prescription")
public class PrescriptionController {
    @Autowired
    private PrescriptionService prescriptionService;

    @GetMapping("/andName")
    public Result getPrescriptionsAndDoctorNamePatientName() {
        List<PrescriptionAndName> data = prescriptionService.getAndDoctorNamePatientName();
        Result result = new Result();
        if (data == null) {
            result.setCode(500);
            result.setMsg("带姓名查询处方信息时发生异常");
        } else {
            result.setCode(200);
            result.setMsg("带姓名查询处方信息成功");
            result.setData(data);
        }
        return result;
    }

    @GetMapping("/andNameByPage/{currentPage}/{pageSize}")
    public Result getPrescriptionsAndDoctorNamePatientNameByPage(@PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        List<PrescriptionAndName> data = prescriptionService.getAndDoctorNamePatientNameByPage(currentPage, pageSize);
        Result result = new Result();
        if (data == null) {
            result.setCode(500);
            result.setMsg("分页带姓名查询处方信息时发生异常");
        } else {
            PageInfo<PrescriptionAndName> pageInfo = new PageInfo<>(data);
            result.setCode(200);
            result.setMsg("分页带姓名查询处方信息成功");
            result.setData(pageInfo);
        }
        return result;
    }
}
